<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增用户信息</title>
    <script src="/js/jquery-3.2.1.min.js"></script>
    <script src="/js/bootstrap/bootstrap.min.js"></script>
    <script src="/js/jquery.hammer/hammer.min.js"></script>
    <script src="/js/jquery.extend.js" type="text/javascript"></script>
    <script src="/js/jquery.scrolltopcontrol/scrolltopcontrol.js"></script>
    <script src="/js/bootstrap.table/bootstrap-table.min.js" type="text/javascript"></script>
    <script src="/js/bootstrap.table/bootstrap-table-zh-CN.min.js" type="text/javascript"></script>
    <script src="/js/dialog.js"></script>
    <script src="/js/comm.js" type="text/javascript"></script>

    <link href="/css/bootstrap/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="/css/bootstrap.table/bootstrap-table.min.css" rel="stylesheet" type="text/css"/>
    <link href="/css/dialog.css" rel="stylesheet" />
    <link href="/css/common.css" rel="stylesheet" type="text/css"/>
</head>
<body style="padding: 0px 6px 0px 6px;overflow-x: hidden;overflow-y: scroll">
<div class="addEdit-title" >
    <h4>新增用户</h4>
</div>
<div style="width: 100%;margin-top: 10px;">
    <form class="form-horizontal" id="articleForm" role="form">
        <div class="form-group">
            <label class="col-sm-2 control-label">登录名<span style="color: red;">*</span></label>
            <div class="col-sm-7">
                <input type="text" class="form-control" id="lgname" name="lgname" onBlur="onBlurValue(this)" placeholder="请输入登录名">
                <span class="help-block" style="color: red; display: none;">请输入登录名</span>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">用户名称<span style="color: red;">*</span></label>
            <div class="col-sm-7">
                <input type="text" class="form-control" style="width: 30%" id="usrname" name="usrname" onBlur="onBlurValue(this)"  placeholder="请输入用户名称">
                <span class="help-block" style="color: red; display: none;">请输入用户名称</span>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">用户电话</label>
            <div class="col-sm-7">
                <input type="text" class="form-control" style="width: 30%" id="usrphone" name="usrphone"  placeholder="请输入用户电话" />
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">描述</label>
            <div class="col-sm-7">
                <input type="text" class="form-control"  id="description" name="description"  />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">用户状态<span style="color: red;">*</span></label>
            <div class="col-sm-7">
                <select class="form-control" id="usrstatus" name="usrstatus" style="width: 20%">
                    <option value="1" >有效</option>
                    <option value="0" >无效</option>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-12 control-label" style="text-align: center;">
                <button type="button" class="btn btn-default" onclick="cancelUser(this)">取消</button>
                <button type="button" class="btn btn-primary" onclick="saveUserInfo(this);">确定</button>
            </label>
        </div>
    </form>
</div>
<a href="#top" id="goTop"><i class="fa fa-angle-up fa-3x"></i></a>
</body>
<script type="text/javascript">
    var idarticle = "";

    $(function () {
        //判断是修改还是新增
        idarticle = getQueryString("id");
        if(idarticle!=null&&idarticle!=""){
            $(".addEdit-title").html("<h4>修改用户内容</h4>");
            getUserInfo(idarticle);
        }

    })

    function saveUserInfo(e){

        var b = saveCheckInfo();
        if(!b){
            return false;
        }
        $(e).attr("disabled","disabled");
        var data ={};
        data["lgname"] = $("#lgname").val();
        data["usrname"] = $("#usrname").val();
        data["usrphone"] = $("#usrphone").val();
        data["description"] = $("#description").val();
        data["usrstatus"] = $("#usrstatus").val();
        if(idarticle==null||idarticle==""){//保存
            $.post("/system/saveUsers.do",data,function (datas) {
                if(datas.value){
                    okDail("保存成功！","/system/userInfo.html");
                }else {
                    errorDail("保存失败!");
                }
            },"json")
        }else {//修改
            data["id"] = idarticle;
            $.post("/system/editUsers.do",data,function (datas) {
                if(datas.value){
                    okDail("修改成功！","/system/userInfo.html?btnPurid="+btnPurid);
                }else {
                    errorDail("修改失败!");
                }
            },"json")
        }

    }

    //判断是否为空
    function saveCheckInfo(){
        var b = true;
        b = checkValue("lgname");
        b = checkValue("usrname");
        return b;
    }

    function getUserInfo(id) {
        $.post("/system/getUserInfo.do",{"id":id},function (data) {
            if(data.value){
                var  message = data.message;
                $("#lgname").val(message.lgname);
                $("#usrname").val(message.usrname);
                $("#usrphone").val(message.usrphone);
                $("#description").val(message.description);
                $("#usrstatus").val(message.usrstatus);

            }else{
                errorDail("获取信息失败!");
            }
        },"json")
    }

    function cancelUser() {
        window.location.href="/system/userInfo.html?btnPurid="+btnPurid;
    }
</script>
</html>